let turnTree = (arr,id='id',pid = 'pid') => {
  for (let j = arr.length - 1; j > 0; j--) {
    let mypid = arr[j][`${pid}`];
    if (mypid == 0) continue; //pid为0没有上一级权限 跳过此次
    for (let q = 0; q < j; q++) {
      if (arr[q][`${id}`] == mypid) {
        //拼接上一级的pid
        if (arr[q][`${pid}`] != 0) arr[j][`${pid}`] += `, ${arr[q][`${pid}`]}`;
        //在上一级的children中添加
        if (!arr[q]["children"]) arr[q]["children"] = [];
        arr[q]["children"] = [arr[j], ...arr[q]["children"]];
        //在上一级的添加之后删除本身
        arr.splice(j, 1);
      }
    }
  }
  return arr;
};

module.exports = turnTree;
